package propcalc_lang.ast;

import java.util.Random;

/** Consecuencia lógica, válida si todas las asignaciones que satisfacen el
 *  antecedente también satisfacen al consecuente.
 *  @author Leonardo Val.
 */
public class Consequence extends Formula {
	public final Proposition premise, conclusion;
	
	public Consequence(Proposition premise, Proposition conclusion) {
		this.premise = premise;
		this.conclusion = conclusion;
	}

	@Override public String unparse() {
		return premise.unparse() +" |= "+ conclusion.unparse();
	}

	public static Consequence generate(Random random, int min, int max) {
		return new Consequence(
			Proposition.generate(random, min-1, max-1),
			Proposition.generate(random, min-1, max-1)
		);
	}
	
	@Override public String toString() {
		return "Consequence("+ premise +", "+ conclusion +")";
	}

	@Override public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((premise == null) ? 0 : premise.hashCode());
		result = prime * result
				+ ((conclusion == null) ? 0 : conclusion.hashCode());
		return result;
	}

	@Override public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Consequence other = (Consequence) obj;
		if (premise == null) {
			if (other.premise != null)
				return false;
		} else if (!premise.equals(other.premise))
			return false;
		if (conclusion == null) {
			if (other.conclusion != null)
				return false;
		} else if (!conclusion.equals(other.conclusion))
			return false;
		return true;
	}

}
